<template>
  <el-dialog title="请确认审核结果" :visible.sync="visible" :close-on-click-modal="false" append-to-body>
    <el-form ref="main-form" status-icon :model="mainQuery" :rules="rules" label-width="120px" label-position="left" :inline="false" style="width: 90%">
      <el-form-item label="审核意见" size="mini" prop="remark">
        <el-input placeholder="" type="textarea" v-model="mainQuery.remark" clearable></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close" size="mini">取 消</el-button>
      <el-popover v-if="rejectVisible" placement="top" width="160" v-model="popRejectVisible">
        <p>确定驳回审核吗?</p>
        <div style="text-align: right; margin: 0">
          <el-button size="mini" type="default" @click="popRejectVisible = false">取消</el-button>
          <el-button type="danger" size="mini" @click="submit(false)" :loading="loading">驳回</el-button>
        </div>
        <el-button slot="reference" size="mini" type="danger" :loading="loading" style="float: left">驳回审核</el-button>
      </el-popover>
      <el-popover placement="top" width="160" v-model="popConfirmVisible">
        <p>确定通过审核吗?</p>
        <div style="text-align: right; margin: 0">
          <el-button size="mini" type="default" @click="popConfirmVisible = false">取消</el-button>
          <el-button type="primary" size="mini" @click="submit(true)" :loading="loading">通过</el-button>
        </div>
        <el-button slot="reference" size="mini" type="primary" :loading="loading" style="margin-left: 10px">通过审核</el-button>
      </el-popover>
    </div>
  </el-dialog>
</template>

<script>

import ApiMain from '@/api/trans.checked';

export default {
  mixins: [
  ],
  props: [
  ],
  data() {
    return {
      channelId: "",
      mainQuery: {
        useApi: false,
        channelId: '',
        isApprove: "",
        remark: "",
      },
      visible: false,
      rejectVisible: false,
      currentRemarkVisible: false,
      popConfirmVisible: false,
      popRejectVisible: false,

      loading: false,
      rules: {
        remark: [
          { required: true, message: '请填写内容', trigger: 'blur' },
        ],
      },

      id: null,
      data: {},

      action: '',
      strType: '',
      currentRemark: '',

    }
  },
  mounted() {
    this.mainQueryRaw = Object.copy(this.mainQuery);
  },

  methods: {

    async show(data, action) {

      console.log(action);

      this.reset();

      this.data = data;

      this.action = action;
      this.rejectVisible = true;
      this.currentRemarkVisible = true;
      this.visible = true;
    },

    close() {
      this.visible = false;
      this.$emit('dialog-close');
    },

    reset() {
      this.$refs['main-form'] && this.$refs['main-form'].resetFields();
      this.id = null;
      this.data = null;
    },

    verifyForm() {
      var bool = true;
      this.$refs['main-form'].validate((valid) => bool = valid);
      return bool;
    },

    async submit(isConfirm) {

      this.popConfirmVisible = false;
      this.popRejectVisible = false;
      var req = Object.copy(this.mainQuery);
      req.id = this.data.id;
      req.isApprove = isConfirm;


      this.loading = true;

      var re = null;

      try {

        if (this.action == 'check') {
          re = await ApiMain.handleBatchReviewFirst(req);
        }
        else {
          re = await ApiMain.handleBatchReviewSecond(req);
        }
        this.$message({ message: '操作成功', type: 'success' });
        this.close();
      } catch (e) { console.error(e) }

      this.loading = false;
    },

  }
}
</script>

<style>
</style>
